package com.fortune.controller;

import com.fortune.base.BaseController;
import com.fortune.dto.excution.WechatProductExcution;
import com.fortune.enums.WechatProductEnum;
import com.fortune.service.WechatProductSevice;
import com.fortune.vo.wechatProduct.Product;
import com.fortune.vo.wechatProduct.TerminalDiscount;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fortune.base.BaseAPIExcution;
import com.fortune.vo.wechatProduct.ProductAndTerminalDiscountVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

@Api(value = "wechat/product", description = "商品相关", tags = {"微信小程序：商品管理"})
@RestController
@RequestMapping("wechat/product")
public class WechatProductController extends BaseController{
	@Autowired
	private WechatProductSevice wechatProductSevice;

	@ApiOperation(value = "商品列表", nickname = "wechatProductList", notes = "", tags={ "@郭阳" })
	@ApiImplicitParams({
			@ApiImplicitParam(name="Authorization", value="登录返回的token值",paramType="header",dataType="String",required = true)
	})
    @GetMapping(value = "list",
        produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<ProductAndTerminalDiscountVo> list() {
		String mid = getMId();
		TerminalDiscount findTerminalDiscount = wechatProductSevice.findTerminalDiscount(mid);
		List<Product> findListProducts = wechatProductSevice.findListProducts(mid);
		ProductAndTerminalDiscountVo productAndTerminalDiscountVo = new ProductAndTerminalDiscountVo();
		productAndTerminalDiscountVo.setTerminalDiscount(findTerminalDiscount);
		productAndTerminalDiscountVo.setProducts(findListProducts);
		if(findTerminalDiscount == null && findListProducts.size() == 0){
			return new WechatProductExcution<ProductAndTerminalDiscountVo>(productAndTerminalDiscountVo, WechatProductEnum.FIND_RESULT_AIR);
		}
		return new WechatProductExcution<ProductAndTerminalDiscountVo>(productAndTerminalDiscountVo, WechatProductEnum.FIND_SUCCESS);

	}
}
